import { BizConfigUtils } from '@/common/biz-config-utils'
import axios from 'axios'
import { PersonModel } from '@/views/person/js/person-model'
import { ResultModel } from '@/common/result.model'

export class PersonApi {
  private static serverAddress = `${BizConfigUtils.getGlobalConfig().serveAddress}/person`
  public static save (data: PersonModel):Promise<ResultModel> {
    console.log('保存用户', data)
    return axios.post(this.serverAddress, data)
  }

  public static query (pageIndex:number, pageSize:number, name = ''):Promise<ResultModel> {
    const url = this.serverAddress + '/page?pageIndex=' + pageIndex + '&pageSize=' + pageSize + (!name ? '' : '&name=' + name)
    return axios.get(url)
  }

  public static get (id:string):Promise<ResultModel> {
    return axios.get(this.serverAddress + '/' + id)
  }

  public static delete (id:string):Promise<ResultModel> {
    return axios.delete(this.serverAddress + '/' + id)
  }

  public static findByUsername (username:string):Promise<ResultModel> {
    return axios.get(this.serverAddress + '/username/' + username)
  }

  public static findByTeamId (teamId:string):Promise<ResultModel> {
    return axios.get(this.serverAddress + '/teamid/' + teamId)
  }
}
